/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2025-05-31 13:58:06
 * @LastEditors: sueRimn
 * @LastEditTime: 2025-07-31 20:32:09
 */

#ifndef _PUBLIC_H
#define _PUBLIC_H

#include "stdbool.h"
#include "stdint.h"
#include "stdlib.h"

#include "step.h"
#include "commun.h"

#include "power.h"
#include "led.h"

#define DYP_RUN_TASK_FREQ   (100)   
#define ICM_RUN_TASK_FREQ   (10)
#define BAT_RUN_TASK_FREQ   (1000)
#define STEP_RUN_TASK_FREQ  (0)     //这个一直运行即可
#define LED_RUN_TASK_FREQ   (100)   //执行频率 100ms执行一次
typedef enum _SEN_STAT
{
    SEN_NOR = 0,
    SEN_ERR
} SEN_STAT_E;

typedef struct _dev_dyp
{
    SEN_STAT_E eDevStat;
    // float fDistance;
    int16_t iDistance;

    bool bIsMeasEndFlag;
    uint32_t uiMeasStartTime;
} dev_dyp_t;

typedef struct _dev_icm
{
    SEN_STAT_E eDevStat;

    int16_t iAnglePit;
    int16_t iAngleRol;
    int16_t iAngleYaw;

    int16_t aucAccArr[3];
    int16_t aucGroArr[3];

} dev_icm_t;

typedef struct _dev_power_monit
{
    SEN_STAT_E eDevStat;
    int16_t sVolVal;
    int16_t sEleVal;
    int16_t sPowerVal;

}dev_power_monit_t;

typedef struct _dev_fall
{
    bool bIsFall1;
    bool bIsFall2;
    bool bIsFall3;
    bool bIsFall4;

    uint16_t *pucFallAdcBuf;
}dev_fall_t;

typedef struct _dev
{
    // float fChargVolVal; // 充电电压
    // float fBatVolVal;   // 电池电压

    bool bIsGetGTMessage;
    bool bIsCharging;               //是否正在充电

    bool bIsOutPowerCtrlPerm;   //是否交出电源控制权限
	  bool bIsRecvCanMessageFlag;
    uint8_t ucPowerStat;        //现在的上下电状态 1上电状态 0未上电状态

    message_fram_t *pstRecvMessage;

    CAN_TxHeaderTypeDef stCanTxHeader;
    uint8_t aucCanTxBuf[8];
    uint32_t uiCanTxMailbox;

    uint32_t uiSysMsTime;

    uint32_t uiDypRunMsTime;
    uint32_t uiIcmRunMsTime;
    uint32_t uiBatChargMsTime;
    uint32_t uiStepMsTime;
    uint32_t uiLedMsTime;

    dev_dyp_t stDevDyp1;
    dev_dyp_t stDevDyp2;
    dev_dyp_t stDevDyp3;
    dev_fall_t stDevFall;
    dev_icm_t stDevIcm;
    dev_power_monit_t stDevBat;
    dev_power_monit_t stDevCharg;
    power_supply_t stDevPowerSupply;
    dev_motor_t stDevMotor;
    // dev_led_t stLightLed;
    // dev_led_t stWriteLed;


} dev_t;


extern dev_t *pstDev;

void dev_init(void);
void magnetCtrl(uint8_t ucOnOffFlag);

#endif